# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Alexey Borzenkov <snaury@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=gcc

pkgname=(
        "${MINGW_PACKAGE_PREFIX}-${_realname}"
        "${MINGW_PACKAGE_PREFIX}-${_realname}-libs"
        "${MINGW_PACKAGE_PREFIX}-${_realname}-libgfortran"
        "${MINGW_PACKAGE_PREFIX}-${_realname}-fortran"
        "${MINGW_PACKAGE_PREFIX}-${_realname}-ada"
        "${MINGW_PACKAGE_PREFIX}-${_realname}-objc"
        )
pkgver=4.9.0
pkgrel=4
pkgdesc="GCC for the MinGW-w64"
arch=('any')
url="http://gcc.gnu.org"
license=('GPL' 'LGPL' 'FDL' 'custom')
groups=("${MINGW_PACKAGE_PREFIX}-toolchain" "${MINGW_PACKAGE_PREFIX}")
depends=("${MINGW_PACKAGE_PREFIX}-${_realname}-ada" "${MINGW_PACKAGE_PREFIX}-zlib" "${MINGW_PACKAGE_PREFIX}-mpc" "${MINGW_PACKAGE_PREFIX}-cloog" "${MINGW_PACKAGE_PREFIX}-crt" "${MINGW_PACKAGE_PREFIX}-binutils" "${MINGW_PACKAGE_PREFIX}-winpthreads" "${MINGW_PACKAGE_PREFIX}-headers")
makedepends=("${MINGW_PACKAGE_PREFIX}-${_realname}" 'lndir')
#checkdepends=('dejagnu')
optdepends=()
options=('strip' '!debug' 'staticlibs' '!emptydirs') # '!buildflags'
source=("ftp://gcc.gnu.org/pub/gcc/releases/${_realname}-${pkgver}/${_realname}-${pkgver}.tar.bz2"
        'gcc-4.9.0-ICE.patch'
        'gcc-4.8-libstdc++export.patch'
        'gcc-4.7-stdthreads.patch'
        '130-dont-escape-arguments-that-dont-need-it-in-pex-win32.c.patch'
        '140-fix-for-windows-not-minding-non-existent-parent-dirs.patch'
        '150-windows-lrealpath-no-force-lowercase-nor-backslash.patch'
        '160-mingw-dont-ignore-native-system-header-dir.patch'
        '170-0001-PR-ipa-60965.patch'
        '180-pr-57440.patch'
        'gcc-4.8-filename-output.patch'
        'gcc-4.9-tree-ssa-threadedge.patch'
        'ktietz-libgomp.patch'
        '4.9.0-libatomic-cygwin.patch'
        'build-more-gnattools.mingw.patch'
        'libgomp-no-static.patch'
        'enable-libitm.mingw.patch'
        'enable-libsanitizer.mingw.patch'
        'enable-shared-gnat.mingw.patch'
        'no-fpic-in-sanitizer.all.patch'
        'port-sanitizer-to-mingw.all.patch'
        'prettify-linking-no-undefined.mingw.patch'
        )
md5sums=('9709b49ae0e904cbb0a6a1b62853b556'
         '627405c8f0ec5cad56b0847adf9ad843'
         'f6b5fb08ff06a7d60ee3280e14240bb2'
         '71cdb550528efcf2a5c9112464bfbabc'
         '4ea64bea762b96cbe69986bd9ddc1532'
         'c9967332940eb2b23820faeb48db6e72'
         '9e07f25b8813191eebd7fda684b1e2dd'
         '60fdccbd072e2b2e724ff879d31ec57e'
         'e3b36213655f047042089e8f38171411'
         '347336d5a318e5e8b3cde29e9174413c'
         '40cb437805e2f7a006aa0d0c3098ab0f'
         '311ece7f5446d550e84e28692d2fb823'
         'f539e602715250bbdb8d2a6a25f1ccbe'
         '9303e0f9cd9c601a1939792123677499'
         'fde1098e5c71963ec2ed4c5b2c4217bd'
         '0a78aaac959e212acb24bb38271804cb'
         '27d5611996e209ba6f6a55ab417386e4'
         '5201bee23601ddfacde436461559f561'
         'a56fb2cf67ae619f22e0d21f378ff704'
         '0f3fb8c9aab4bbb02a9923adc22c6109'
         '52592c1d7c6031ff601ecfdf3942b940'
         '09bdad41515c8d353612f30c91b3bac2')
_threads="posix"

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}

  #remove files the patches will create (so they aren't in the way the 2nd time round)
  [ -f gcc/testsuite/g++.dg/cpp0x/lambda/lambda-names1.C ] && rm gcc/testsuite/g++.dg/cpp0x/lambda/lambda-names1.C
  [ -f gcc/testsuite/g++.dg/ipa/devirt-32.C ] && rm gcc/testsuite/g++.dg/ipa/devirt-32.C

  #do not install libiberty
  sed -i 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in

  # hack! - some configure tests for header files using "$CPP $CPPFLAGS"
  sed -i "/ac_cpp=/s/\$CPPFLAGS/\$CPPFLAGS -O2/" {libiberty,gcc}/configure

  # do not expect $prefix/mingw symlink - this should be superceded by
  # 160-mingw-dont-ignore-native-system-header-dir.patch .. but isn't!
  [[ -f configure.src ]] && {
    rm -f configure
    cp configure.src configure
  } || {
    cp configure configure.src
  }
  sed -i 's/${prefix}\/mingw\//${prefix}\//g' configure
  
  # change hardcoded /mingw prefix to the real prefix
  [[ -f gcc/config/i386/mingw32.h.src ]] && {
    rm -f gcc/config/i386/mingw32.h
    cp gcc/config/i386/mingw32.h.src gcc/config/i386/mingw32.h
  } || {
    cp gcc/config/i386/mingw32.h gcc/config/i386/mingw32.h.src
  }
  local MINGW_NATIVE_PREFIX=$(cygpath -am ${MINGW_PREFIX}/${MINGW_CHOST})
  sed -i "s/\\/mingw\\//${MINGW_NATIVE_PREFIX//\//\\/}\\//g" gcc/config/i386/mingw32.h
  
  # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60830
  patch -p1 -i ${srcdir}/gcc-4.9.0-ICE.patch
  
  patch -p1 -i ${srcdir}/gcc-4.8-libstdc++export.patch
  patch -p1 -i ${srcdir}/gcc-4.7-stdthreads.patch

  # Don't waste valuable commandline chars on double-quotes around "arguments"
  #  that don't need them.
  patch -p1 -i ${srcdir}/130-dont-escape-arguments-that-dont-need-it-in-pex-win32.c.patch

  # Make Windows behave the same as Posix in the consideration of whether folder
  # "/exists/doesnt-exist/.." is a valid path.. in Posix, it isn't.
  patch -p1 -i ${srcdir}/140-fix-for-windows-not-minding-non-existent-parent-dirs.patch

  # Don't make a lowercase backslashed path from argv[0]
  #  that then fail to strcmp with prefix(es) .. they're also ugly.
  patch -p1 -i ${srcdir}/150-windows-lrealpath-no-force-lowercase-nor-backslash.patch

  # Don't ignore values passed via --with-native-system-header-dir=
  # patch -p1 -i ${srcdir}/160-mingw-dont-ignore-native-system-header-dir.patch

  # Fixes crash in javascriptcore/JavaScriptCore/runtime/JSGlobalData.cpp
  #  JSGlobalData::storeVPtrs() to do with placement new and POD vs non-POD.
  # https://bugreports.qt-project.org/browse/QTBUG-38733
  # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60965
  patch -p1 -i ${srcdir}/170-0001-PR-ipa-60965.patch

  patch -p1 -i ${srcdir}/180-pr-57440.patch

  # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57653
  patch -p0 -i ${srcdir}/gcc-4.8-filename-output.patch

  # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60902
  patch -p1 -i ${srcdir}/gcc-4.9-tree-ssa-threadedge.patch

  # Kai's libgomp fix.
  patch -p1 -i ${srcdir}/ktietz-libgomp.patch
  
  # Enable building libatomic
  patch -p2 -i ${srcdir}/4.9.0-libatomic-cygwin.patch
  
  # Build aextra tools for Ada
  patch -p1 -i ${srcdir}/build-more-gnattools.mingw.patch

  # patch -p1 -i ${srcdir}/enable-libitm.mingw.patch
  # patch -p1 -i ${srcdir}/enable-libsanitizer.mingw.patch
  # patch -p1 -i ${srcdir}/enable-shared-gnat.mingw.patch
  # patch -p1 -i ${srcdir}/no-fpic-in-sanitizer.all.patch
  # patch -p1 -i ${srcdir}/port-sanitizer-to-mingw.all.patch
  # patch -p1 -i ${srcdir}/prettify-linking-no-undefined.mingw.patch
  
  if check_option "debug" "y"; then
    # Expose some libgomp internals for debugging.
    patch -p1 -i ${srcdir}/libgomp-no-static.patch
  fi
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  case "${CARCH}" in
    i686)
      local _conf="--disable-sjlj-exceptions --with-dwarf2"
      #LDFLAGS+=" -Wl,--large-address-aware"
      local _arch=i686
    ;;
    
    x86_64)
      local _arch=x86-64
      local _conf=""
    ;;
  esac

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --with-local-prefix=${MINGW_PREFIX}/local \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --with-native-system-header-dir=${MINGW_PREFIX}/${MINGW_CHOST}/include \
    --libexecdir=${MINGW_PREFIX}/lib \
    --with-gxx-include-dir=${MINGW_PREFIX}/include/c++/${pkgver} \
    --enable-bootstrap \
    --with-arch=${_arch} \
    --with-tune=generic \
    --enable-languages=c,lto,c++,objc,obj-c++,fortran,ada \
    --enable-shared --enable-static \
    --enable-libatomic \
    --enable-threads=${_threads} \
    --enable-graphite \
    --enable-fully-dynamic-string \
    --enable-libstdcxx-time=yes \
    --disable-libstdcxx-pch \
    --disable-libstdcxx-debug \
    --enable-cloog-backend=isl \
    --enable-version-specific-runtime-libs \
    --disable-cloog-version-check --disable-isl-version-check \
    --enable-lto \
    --enable-libgomp \
    --disable-multilib \
    --enable-checking=release \
    --disable-rpath \
    --disable-win32-registry \
    --disable-nls \
    --disable-werror \
    --disable-symvers \
    --with-libiconv \
    --with-system-zlib \
    --with-{gmp,mpfr,mpc,isl,cloog}=${MINGW_PREFIX} \
    --with-pkgversion="Rev${pkgrel}, Built by MSYS2 project" \
    --with-bugurl="http://sourceforge.net/projects/msys2" \
    --with-gnu-as --with-gnu-ld \
    ${_conf}
    #--enable-libitm
    #--enable-objc-gc

  # While we're debugging -fopenmp problems at least.
  # .. we may as well not strip anything.
  if check_option "strip" "n"; then
    sed -i 's,^STRIP = .*$,STRIP = true,g'                   Makefile
    sed -i 's,^STRIP_FOR_TARGET=.*$,STRIP_FOR_TARGET=true,g' Makefile
  fi

  make all

  make -j1 DESTDIR=${srcdir} install
  mv ${srcdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/adalib/*.dll ${srcdir}${MINGW_PREFIX}/bin/
}

package_mingw-w64-gcc-libs() {
  pkgdesc="GNU Compiler Collection (libraries) for MinGW-w64"
  depends=("${MINGW_PACKAGE_PREFIX}-gmp" "${MINGW_PACKAGE_PREFIX}-libwinpthread")
  mkdir -p ${pkgdir}${MINGW_PREFIX}/bin

  cd ${srcdir}${MINGW_PREFIX}
  cp bin/{libatomic*,libgcc*,libgomp*,libquadmath*,libssp*,libstdc*}.dll ${pkgdir}${MINGW_PREFIX}/bin/
}

package_mingw-w64-gcc() {
  pkgdesc="GNU Compiler Collection (C,C++,OpenMP) for MinGW-w64"
  depends=("${MINGW_PACKAGE_PREFIX}-crt" "${MINGW_PACKAGE_PREFIX}-binutils" "${MINGW_PACKAGE_PREFIX}-winpthreads" "${MINGW_PACKAGE_PREFIX}-headers" "${MINGW_PACKAGE_PREFIX}-zlib" "${MINGW_PACKAGE_PREFIX}-mpc" "${MINGW_PACKAGE_PREFIX}-cloog" "${MINGW_PACKAGE_PREFIX}-${_realname}-libs=${pkgver}") 
  provides=("${MINGW_PACKAGE_PREFIX}-${_realname}-base")
  conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-base")

  mkdir -p ${pkgdir}${MINGW_PREFIX}/{bin,include,lib,share}
  
  cd ${srcdir}${MINGW_PREFIX}
  cp bin/cpp.exe ${pkgdir}${MINGW_PREFIX}/bin/
  cp bin/gcc.exe ${pkgdir}${MINGW_PREFIX}/bin/
  cp bin/gcc-ar.exe ${pkgdir}${MINGW_PREFIX}/bin/
  cp bin/gcc-nm.exe ${pkgdir}${MINGW_PREFIX}/bin/
  cp bin/gcc-ranlib.exe ${pkgdir}${MINGW_PREFIX}/bin/
  cp bin/gcov.exe ${pkgdir}${MINGW_PREFIX}/bin/
  cp bin/c++.exe ${pkgdir}${MINGW_PREFIX}/bin/
  cp bin/g++.exe ${pkgdir}${MINGW_PREFIX}/bin/
  cp bin/${MINGW_CHOST}-c++.exe ${pkgdir}${MINGW_PREFIX}/bin/
  cp bin/${MINGW_CHOST}-g++.exe ${pkgdir}${MINGW_PREFIX}/bin/
  cp bin/${MINGW_CHOST}-gcc-${pkgver}.exe ${pkgdir}${MINGW_PREFIX}/bin/
  cp bin/${MINGW_CHOST}-gcc.exe ${pkgdir}${MINGW_PREFIX}/bin/
  cp bin/${MINGW_CHOST}-gcc-ar.exe ${pkgdir}${MINGW_PREFIX}/bin/
  cp bin/${MINGW_CHOST}-gcc-nm.exe ${pkgdir}${MINGW_PREFIX}/bin/
  cp bin/${MINGW_CHOST}-gcc-ranlib.exe ${pkgdir}${MINGW_PREFIX}/bin/
  
  #cp bin/{libgcc*,libgomp*,libquadmath*,libssp*,libstdc*}.dll ${pkgdir}${MINGW_PREFIX}/bin/
  mkdir -p ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/include
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/include/*.h ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/include/
  cp -r lib/gcc/${MINGW_CHOST}/${pkgver}/include/ssp ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/include/
  cp -r lib/gcc/${MINGW_CHOST}/${pkgver}/include-fixed ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp -r lib/gcc/${MINGW_CHOST}/${pkgver}/install-tools ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/cc1.exe ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/collect2.exe ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/crt*.o ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/liblto* ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/libatomic* ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/libgcc* ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/libgcov.* ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/libgomp.* ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/libquadmath.* ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/libssp* ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/lto*.exe ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
    
  #mkdir -p ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/lib
  cp ${srcdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/lib/libgcc_s.a ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  #cp lib/gcc/${MINGW_CHOST}/lib/libgcc_s.a ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/lib/
  
  #cp -r lib/gcc/${MINGW_CHOST}/${pkgver}/include/c++ ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/include/
  cp -r include/c++ ${pkgdir}${MINGW_PREFIX}/include/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/cc1plus.exe ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/libstdc++* ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/libsupc++* ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  
  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/{doc,info,locale,man}
  #cp -r share/doc/gcc-${pkgver} ${pkgdir}${MINGW_PREFIX}/share/doc/
  cp share/info/cpp.info* ${pkgdir}${MINGW_PREFIX}/share/info/
  cp share/info/cppinternals.info* ${pkgdir}${MINGW_PREFIX}/share/info/
  cp share/info/gcc.info* ${pkgdir}${MINGW_PREFIX}/share/info/
  cp share/info/gccinstall.info* ${pkgdir}${MINGW_PREFIX}/share/info/
  cp share/info/gccint.info* ${pkgdir}${MINGW_PREFIX}/share/info/
  cp share/info/libgomp.info* ${pkgdir}${MINGW_PREFIX}/share/info/
  cp share/info/libquadmath.info* ${pkgdir}${MINGW_PREFIX}/share/info/
  
  #cp share/locale/* ${pkgdir}${MINGW_PREFIX}/share/locale/
  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/gcc-${pkgver}/python
  cp -r share/gcc-${pkgver}/python/libstdcxx  ${pkgdir}${MINGW_PREFIX}/share/gcc-${pkgver}/python/
  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/man/man1
  cp share/man/man1/cpp.1* ${pkgdir}${MINGW_PREFIX}/share/man/man1/
  cp share/man/man1/gcc.1* ${pkgdir}${MINGW_PREFIX}/share/man/man1/
  cp share/man/man1/gcov.1* ${pkgdir}${MINGW_PREFIX}/share/man/man1/
  cp share/man/man7/fsf-funding.7* ${pkgdir}${MINGW_PREFIX}/share/man/man1/
  cp share/man/man7/gfdl.7* ${pkgdir}${MINGW_PREFIX}/share/man/man1/
  cp share/man/man7/gpl.7* ${pkgdir}${MINGW_PREFIX}/share/man/man1/
  cp share/man/man1/g++.1* ${pkgdir}${MINGW_PREFIX}/share/man/man1/
}

package_mingw-w64-gcc-libgfortran() {
  pkgdesc="GNU Compiler Collection (libgfortran) for MinGW-w64"
  depends=("${MINGW_PACKAGE_PREFIX}-${_realname}-libs=${pkgver}")
  
  mkdir -p ${pkgdir}${MINGW_PREFIX}/bin
  cd ${srcdir}${MINGW_PREFIX}
  cp bin/libgfortran*.dll ${pkgdir}${MINGW_PREFIX}/bin/
}

package_mingw-w64-gcc-fortran() {
  pkgdesc="GNU Compiler Collection (Fortran) for MinGW-w64"
  depends=("${MINGW_PACKAGE_PREFIX}-${_realname}=${pkgver}" "${MINGW_PACKAGE_PREFIX}-${_realname}-libgfortran=${pkgver}")
  
  mkdir -p ${pkgdir}${MINGW_PREFIX}/{bin,lib,share}
  
  cd ${srcdir}${MINGW_PREFIX}
  cp bin/gfortran.exe ${pkgdir}${MINGW_PREFIX}/bin/
  cp bin/${MINGW_CHOST}-gfortran.exe ${pkgdir}${MINGW_PREFIX}/bin/
  
  #cp bin/libgfortran*.dll ${pkgdir}${MINGW_PREFIX}/bin/
  
  mkdir -p ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}
  cp -r lib/gcc/${MINGW_CHOST}/${pkgver}/finclude  ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/f951.exe  ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/libcaf_single.a  ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/libgfortran*  ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/man/man1
  cp share/man/man1/gfortran.1* ${pkgdir}${MINGW_PREFIX}/share/man/man1/
  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/info
  cp share/info/gfortran.info* ${pkgdir}${MINGW_PREFIX}/share/info/
}

package_mingw-w64-gcc-ada() {
  pkgdesc="GNU Compiler Collection (Ada) for MinGW-w64"
  depends=("${MINGW_PACKAGE_PREFIX}-${_realname}=${pkgver}")

  mkdir -p ${pkgdir}${MINGW_PREFIX}/{bin,lib,share}
  
  cd ${srcdir}${MINGW_PREFIX}
  cp bin/gnat*.exe ${pkgdir}${MINGW_PREFIX}/bin/
  # cp bin/gnatbind.exe ${pkgdir}${MINGW_PREFIX}/bin/
  # cp bin/gnatchop.exe ${pkgdir}${MINGW_PREFIX}/bin/
  # cp bin/gnatclean.exe ${pkgdir}${MINGW_PREFIX}/bin/
  # cp bin/gnatdll.exe ${pkgdir}${MINGW_PREFIX}/bin/
  # cp bin/gnatfind.exe ${pkgdir}${MINGW_PREFIX}/bin/
  # cp bin/gnatkr.exe ${pkgdir}${MINGW_PREFIX}/bin/
  # cp bin/gnatlink.exe ${pkgdir}${MINGW_PREFIX}/bin/
  # cp bin/gnatls.exe ${pkgdir}${MINGW_PREFIX}/bin/
  # cp bin/gnatmake.exe ${pkgdir}${MINGW_PREFIX}/bin/
  # cp bin/gnatname.exe ${pkgdir}${MINGW_PREFIX}/bin/
  # cp bin/gnatprep.exe ${pkgdir}${MINGW_PREFIX}/bin/
  # cp bin/gnatxref.exe ${pkgdir}${MINGW_PREFIX}/bin/
  
  cp bin/{libgnarl*,libgnat*}.dll ${pkgdir}${MINGW_PREFIX}/bin/
  
  mkdir -p ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}
  cp -r lib/gcc/${MINGW_CHOST}/${pkgver}/adainclude ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp -r lib/gcc/${MINGW_CHOST}/${pkgver}/adalib ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/gnat1.exe ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  
  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/info
  cp share/info/gnat-style.info* ${pkgdir}${MINGW_PREFIX}/share/info/
  cp share/info/gnat_rm.info* ${pkgdir}${MINGW_PREFIX}/share/info/
  cp share/info/gnat_ugn.info* ${pkgdir}${MINGW_PREFIX}/share/info/
}

package_mingw-w64-gcc-objc() {
  pkgdesc="GNU Compiler Collection (ObjC,Obj-C++) for MinGW-w64"
  depends=("${MINGW_PACKAGE_PREFIX}-${_realname}=${pkgver}")
  
  mkdir -p ${pkgdir}${MINGW_PREFIX}/{bin,lib}
  
  cd ${srcdir}${MINGW_PREFIX}
  cp bin/libobjc*.dll ${pkgdir}${MINGW_PREFIX}/bin/
  
  mkdir -p ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/include
  cp -r lib/gcc/${MINGW_CHOST}/${pkgver}/include/objc ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/include/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/cc1obj.exe ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/libobjc.* ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
  cp lib/gcc/${MINGW_CHOST}/${pkgver}/cc1objplus.exe ${pkgdir}${MINGW_PREFIX}/lib/gcc/${MINGW_CHOST}/${pkgver}/
}

# Wrappers for package functions

# 32-bit wrappers
package_mingw-w64-i686-gcc-libs() {
  package_mingw-w64-gcc-libs
}

package_mingw-w64-i686-gcc() {
  package_mingw-w64-gcc
}

package_mingw-w64-i686-gcc-libgfortran() {
  package_mingw-w64-gcc-libgfortran
}

package_mingw-w64-i686-gcc-fortran() {
  package_mingw-w64-gcc-fortran
}

package_mingw-w64-i686-gcc-ada() {
  package_mingw-w64-gcc-ada
}

package_mingw-w64-i686-gcc-objc() {
  package_mingw-w64-gcc-objc
}

# 64-bit wrappers
package_mingw-w64-x86_64-gcc-libs() {
  package_mingw-w64-gcc-libs
}

package_mingw-w64-x86_64-gcc() {
  package_mingw-w64-gcc
}

package_mingw-w64-x86_64-gcc-libgfortran() {
  package_mingw-w64-gcc-libgfortran
}

package_mingw-w64-x86_64-gcc-fortran() {
  package_mingw-w64-gcc-fortran
}

package_mingw-w64-x86_64-gcc-ada() {
  package_mingw-w64-gcc-ada
}

package_mingw-w64-x86_64-gcc-objc() {
  package_mingw-w64-gcc-objc
}
